<extend name="Base/common"/>
<block name="style">
    <style type="text/css">
        .form_mian{}
        .form_mian .title{text-align: center;padding-top: 3em;line-height: 4em;}
        .form_mian .fomr-b{padding-top: 10px;}
        .form_mian .fomr-b li{width: 40%;float: left;margin-left: 5%;color: #1aad19;text-align: center;line-height: 2em;border:2px solid rgba(26, 173, 25);border-radius:10px;font-size: 1.5em;}
        .form_mian .fomr-b li.current{background-color: #1aad19;color: #fff;}
        .form_mian .fomr-text{padding-top: 10px;}
        .form_mian .fomr-text li{width: 40%;float: left;margin-left: 5%;color: #999;line-height: 2em;}
    </style>
</block>
<block name="body">
    <div class="content">
        <div class="bdr-b pd-t-3">
            <p class="font32 lh1-6">请选择借款金额</p>
            <ul class="loan-item clearfix typemoney">
                
                <foreach name="volist" item="vo" key="key" >
                    <if condition="$key eq 0 ">
                        <li data-id="{$vo.id}" data-price="{$vo.price}" data-days_qin="{$vo.days_qin}" data-vetting1_qin="{$quota?0:$vo.vetting1_qin}" data-accrual_qin="{$vo.accrual_qin}" data-manag_qin="{$quota?0:$vo.manag_qin}" data-days_shi="{$vo.days_shi}" data-vetting1_shi="{$quota?0:$vo.vetting1_shi}" data-accrual_shi="{$vo.accrual_shi}" data-manag_shi="{$quota?0:$vo.manag_shi}" class="blue-hr" style="float:left">{$vo.price} 元</li>
                        <else />
                        <li data-id="{$vo.id}" data-price="{$vo.price}" data-days_qin="{$vo.days_qin}" data-vetting1_qin="{$quota?0:$vo.vetting1_qin}" data-accrual_qin="{$vo.accrual_qin}" data-manag_qin="{$quota?0:$vo.manag_qin}" data-days_shi="{$vo.days_shi}" data-vetting1_shi="{$quota?0:$vo.vetting1_shi}" data-accrual_shi="{$vo.accrual_shi}" data-manag_shi="{$quota?0:$vo.manag_shi}" style="float: right;">{$vo.price} 元</li>
                    </if>
                </foreach>
            </ul>
        </div>
        <div>
            <p class="font32 lh1-6 mg-t-3 ">请选择借款时长</p>
            <ul class="loan-item clearfix typetime">
                <li data-day="7" class="orange-hr">7天</li>
                <li data-day="14">14天</li>
            </ul>
        </div>
        <div class="loan-shm">
            <p>总费：<span class="blue zhongshu">0.00</span>元</p>
            到期应还：<span class="blue repayment">0.00</span>元<br>
            实际到账：<span class="orange payable">0.00</span>元
        </div>
        

        <p style="margin-left:0.5em;margin-top:3%"><img src="__IMG__/tishi.png" style="height:18px;width:18px;margin-top:2px;margin-right:5px;"/>禁止在校学生申请借款</p>
        <input type="button" data-url="{:U('')}" value="提 交" class="login-btn" />

    </div>

</block>
<block name="script">
    <script >
        function returnFloat(val){
            var val=Math.round(parseFloat(val)*100)/100;
            var xsd=val.toString().split(".");
            if(xsd.length==1){
                val=val.toString()+".00";
                return val;
            }
            if(xsd.length>1){
                if(xsd[1].length<2){
                    val=val.toString()+"0";
                }
                return val;
            }
        }

        function settlement(){
            var typemoney,days_qin,vetting1_qin,accrual_qin,manag_qin,days_shi, vetting1_shi, accrual_shi,manag_shi,typetime,day,vetting1,accrual,manag,money,price;
            typemoney = $('.typemoney .blue-hr');
            days_qin        =  typemoney.attr('data-days_qin');
            vetting1_qin    =  typemoney.attr('data-vetting1_qin');
            accrual_qin     =  typemoney.attr('data-accrual_qin');
            manag_qin       =  typemoney.attr('data-manag_qin');
            days_shi        =  typemoney.attr('data-days_shi');
            vetting1_shi    =  typemoney.attr('data-vetting1_shi');
            accrual_shi     =  typemoney.attr('data-accrual_shi');
            manag_shi       =  typemoney.attr('data-manag_shi');
            price       =  typemoney.attr('data-price');
            money = parseFloat(price);
            $('.repayment').html(money);
            typetime = $('.typetime .orange-hr');
            day             =  typetime.attr('data-day');
            if(day == 7){
                 vetting1    = parseFloat(vetting1_qin);
                 accrual     = parseFloat(accrual_qin);
                 manag       =parseFloat(manag_qin);

            }else{
                
                vetting1    = parseFloat(vetting1_shi);
                accrual     = parseFloat(accrual_shi);
                manag       = parseFloat(manag_shi);
            }

            var zhongshu = (vetting1+accrual+manag)/100*money;
            zhongshu=Math.round(zhongshu*100)/100;
            var payable = returnFloat(parseInt(money)-zhongshu);

            $('.payable').html(payable);
            $('.zhongshu').html(zhongshu);
            $('.vetting1').html(vetting1);
            $('.accrual').html(accrual);
            $('.manag').html(manag);

        }


        Zepto(function($){
            settlement();
            //时间选择
            $('.typetime li').click(function(){
                // popup..alert()
                $('.typetime li').removeClass('orange-hr');
                $(this).addClass('orange-hr');
                settlement();
            });
            //借款金额选择
            $('.typemoney li').click(function(){
                $('.typemoney li').removeClass('blue-hr');
                $(this).addClass('blue-hr');
                settlement();
            });

            

            $('.login-btn').click(function(){
               var typemoney =  $('.typemoney .blue-hr');
               var typetime  =  $('.typetime .orange-hr');
               var day       =  typetime.attr('data-day');
               var id        =  typemoney.attr('data-id');
               var data      =  {day:day,id:id};
               var Url       =  $(this).attr('data-url');
              

               $.ajax({
                    type:'post',
                    url:Url,
                    data:data,
                    // dataType:'json',
                    beforeSend:function(XMLHttpRequest){
                        popup.loading('正在提交中');
                    },
                    success:function(data){
                        if(data.status==true){
                            popup.alert(data.info,data.url);
                        }else{
                            // if(data.id>0){  //有ID  缴费

                            //     confirm(data.info);  //缴纳费用
                            //     location.href="{:U('alipay?type=jiaoyi&id=')}"+data.id;
                            // }else{
                                popup.alert(data.info,data.url);
                            // }


                        }
                    },
                    complete:function(XMLHttpRequest,textStatus){
                        popup.noloading();
                    },
                    error:function(m){
                        // popup.alert(m.status)
                        //请求出错处理
                        popup.alert('请求出错处理');
                        return false;
                    }
                });

            });





        });
    </script>

</block>